const { sequelize, DataTypes } = require('../utill/getSequelize')

const { T_subjects } = require('./t_exam_subjects')
const { T_exam_target } = require('./t_exam_target')
//标签表
const T_exam_label = sequelize.define('T_exam_label', {

    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true,
    },


    //外键
    sub_id: {
        type: DataTypes.INTEGER,
    },

    target_id: {
        type: DataTypes.INTEGER,
    },

    label: {
        type: DataTypes.STRING,
    }
});



//外键关联操作
T_exam_label.belongsTo(T_subjects, {
    foreignKey: 'sub_id',
    targetKey: 'id',
});

T_exam_label.belongsTo(T_exam_target, {
    foreignKey: 'target_id',
    targetKey: 'id',
});


//同步模型和数据库表
(async () => {
    try {
        await sequelize.sync({ force: false });
        console.log('All models were synchronized successfully.');
    } catch (error) {
        console.log(error);
    }

})();

//提供出去
module.exports = { T_exam_label };